Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
Is the letter "f" necessary if the decimal point is written?

What is the difference between the 2 following code lines?

#define F_SAMP 10000.0f

#define F_SAMP 10000.0

Aren't both float? (By the way, in this particular case compiler is XC16 but I do not think that matters too much) Thanks for the attention

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Is the letter "f" necessary if the decimal point is written?

Not necessary, but best to use f-less constants with double variables/math and f suffixed constants with float ones.

Aren't both float?

There are both floating-point.
But float and double are different.

Type difference

Appending an f make a floating point constant type float rather than double.

This can steer to different code with _Generic and <tgmath.h> as well as the math used in a floating-point expression.

Given the usual range and precision difference, subtle and sometimes not so subtle differences will occur.

Value difference

The f tell the compiler to use the usually narrower range and precision of a float.
e.g. 0.1 != 0.1f.

Sometimes it makes a value difference too, even when assigned to a float.

over 4 years ago · Santiago Trujillo Denunciar

0

Floating-point constants with an f or F suffix have type float, with no suffix have type double, and with an l or L suffix have type long double.

First, this makes a difference because the value can be different, and usually will be different if the value is not an integer. For example, using the formats most commonly used for float and double, the value of 123456789. is 123,456,789, but the value of 123456789.f is 123,456,792.

Further, if the value is assigned to a float, the result may be different than if the constant used f originally. For example, after:

float f0 = 9007198986305535.5f;
float f1 = 9007198986305535.5;

The value of f0 is 9,007,198,717,870,080, but the value of f1 is 9,007,199,254,740,992. This is because the former rounds 9,007,198,986,305,535.5 directly to float, but the latter rounds first to double and then to float.

over 4 years ago · Santiago Trujillo Denunciar

0

The f suffix makes the constant 10000.0f have type float.

The constant 10000.0 has type double.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda